﻿using UnityEngine;
using System.Collections;

public class CameraMove : MonoBehaviour
{
    public float m_fScenMoveSpeed = 10;
    public float m_fScenScrollSpeed = 10;
    public float m_fScenRotateSpeed = 100;
    private Ray m_rayTranslate = new Ray(Vector3.zero, new Vector3(0,1,0));
    // Use this for initialization
    void Start () {
        Loom.Initialize();
	}
	void UpdateWithNoCollision()
    {
        Vector3 dir;
        float x =0, y = 0, z= 0;
        if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
        {
            z += 1;
        }
        if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
        {
            z -= 1;
        }
        if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
        {
            x -= 1;
        }
        if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
        {
            x += 1;
        }
        if (Input.GetMouseButton(0))
        {
            x += Input.GetAxis("Mouse X");
            y += Input.GetAxis("Mouse Y");
           
        }
        dir = new Vector3(x, y, z);
        transform.Translate(dir * m_fScenMoveSpeed * Time.deltaTime);
        //////////////////////////////////////////////////
        x = Input.GetAxis("Mouse ScrollWheel");
        dir = new Vector3(0, 0, x);
        transform.Translate(dir * m_fScenScrollSpeed * Time.deltaTime);

        //旋转
        if (Input.GetMouseButton(2))
        {
            x = Input.GetAxis("Mouse X");
            y = Input.GetAxis("Mouse Y");
            transform.Rotate(new Vector3(0,1,0), x * m_fScenRotateSpeed* Time.deltaTime);
            transform.Rotate(new Vector3(1, 0, 0), y * m_fScenRotateSpeed * Time.deltaTime);
        }
        if(Mathf.Abs(transform.rotation.eulerAngles.y) > 2)
        {
            transform.rotation.eulerAngles.Set(transform.rotation.eulerAngles.x, 0, transform.rotation.eulerAngles.z);
        }
    }
	// Update is called once per frame
	void Update ()
    {
        UpdateWithNoCollision();
    }
}
